import $api from '.';

interface EventParams {
  name: string; // 赛事名称
  peopleLimit: string; // 人数限制
  startMoney?: string | number; // 起始金额
  uid: string;
  enrollStime: Date;
  enrollEtime: Date;
  desc: string;
  jf: string;
}

// 添加赛事

const addEvent = async (data: EventParams) => {
  const res = await $api.post('/event', {
    ...data,
  });

  return res;
};

// 修改赛事
const editEvent = async (id: string | number, data: EventParams) => {
  const res = await $api.patch(`/event/${id}`, {
    ...data,
  });
  return res;
};

// 删除
const delEvent = async (id: string | number) => {
  const res = await $api.delete(`/event/${id}`);
  return res;
};

// 查一个
const getEvent = async (id: string | number) => {
  const res = await $api.get(`/event/${id}`);
  return res;
};

// 获取列表
const getEventList = async ({ keyword, $limit = 10, $page = 1 }: any) => {
  const $skip = ($page - 1) * $limit;
  let queryStr = '';
  if (keyword) queryStr += `&name=${keyword}`;

  const res = await $api.get(`/event?$limit=${$limit}&$skip=${$skip}${queryStr}`);
  return res;
};

export default {
  addEvent,
  editEvent,
  delEvent,
  getEvent,
  getEventList,
};
